<%inherit file="base.html"/>

<%block name="content">
<style>
    .label-log {
        background: limegreen;
        text-align: center;
        color: white;
    }
</style>
<div class="king-layout2-main mt15" style="width:960px;">
    <div class="container-fluid mb0 ">
        <form method="post" action="">
            <input type="hidden" name="csrfmiddlewaretoken" value="${csrf_token}">
            <div class="row">
                <div class="col-md-12">
                    <div class="form-group clearfix ">
                        <label class="col-sm-3 control-label bk-lh30 pt0">选择业务：</label>
                        <div class="col-sm-9">
                            <select name="bk_biz_id" id="bk_biz_id" class="form-control bk-valign-top">
                                % for biz in bizs:
                                <option value="${biz['bk_biz_id']}" ${'selected' if ( int(biz['bk_biz_id']) == int(bkBizId) ) else ''}>${biz['bk_biz_name']}</option>
                                % endfor
                            </select>
                        </div>
                    </div>
                    <div class="form-group clearfix ">
                        <label class="col-sm-3 control-label bk-lh30 pt0">输入内网IP：</label>
                        <div class="col-sm-9">
                            <input type="text" name="ip" class="form-control bk-valign-top" id="ip" placeholder="仅支持内部IP查询" value="${ip}">
                        </div>
                    </div>
                    <div class="form-group clearfix">
                        <div class="col-sm-9 col-sm-offset-3">
                            <button type="submit" class="king-btn mr10  king-success">查询</button>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div class="panel panel-default mb0">
        <div class="panel-heading"> 查询结果</div>
        <table class="table mb0 pr15 ranger-box2" id="table">
            <thead>
            <tr>
                <th style="width: 70px;">#</th>
                <th>IP</th>
                <th>Mem/Disk/CPU</th>
                <th>最后巡检时间</th>
                <!--<th>大区</th>-->
                <!--<th>模块</th>-->
                <th>云区域</th>
                <th>系统类型</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
             % for host in hosts:
            <tr>
                <td style="width: 70px;">${loop.index}</td>
                <td>${host['bk_host_innerip']}</td>
                <td class="label-log">--</td>
                <td>--</td>
                <!--<td></td>-->
                <!--<td></td>-->
                % if len(host['bk_cloud_id']) > 0 :
                <td>${host['bk_cloud_id'][0]['bk_inst_name']}</td>
                % else:
                <td>--</td>
                % endif
                <td>${host['bk_os_type']}</td>
                <td>
                    <button name="search" data-ip="${host['bk_host_innerip']}" class="btn btn-xs btn-success check"><i class="glyphicon glyphicon-search"></i></button>
                    <button name="plus" data-ip="${host['bk_host_innerip']}" class="btn btn-xs btn-warning check"><i class="glyphicon glyphicon-plus"></i></button>
                    <button name="minus" data-ip="${host['bk_host_innerip']}" class="btn btn-xs btn-danger check"><i class="glyphicon glyphicon-minus"></i></button>
                </td>
            </tr>
            % endfor
            </tbody>
        </table>
    </div>
</div>
<script>
    $(function(){
        $("#table").on('click','[name="search"]',function(e){
            alert('后台查询中，请稍后...')

            var bk_biz_id = $("#bk_biz_id").val();
            var data = $(this).data();

            var $tdLog = $(this).parents('tr').children('td:nth-child(3)');
            var $tdLogTime = $(this).parents('tr').children('td:nth-child(4)');

            $.post('${SITE_URL}check_host', {
                'bk_biz_id': bk_biz_id,
                'bk_host_innerip': data.ip
            }, function (res) {
                console.log(res);
                $tdLog.text(res.data.log);
                $tdLogTime.text(res.data.time);
                alert(res.message);
            })

        });

        $("#table").on('click','[name="plus"]',function(e){

            var bk_biz_id = $("#bk_biz_id").val();
            var data = $(this).data();

            $.post('${SITE_URL}add_check_host', {
                'bk_biz_id': bk_biz_id,
                'bk_host_innerip': data.ip
            }, function (res) {
                console.log(res);
                alert(res.message);
            })
        });

        $("#table").on('click','[name="minus"]',function(e){
            var bk_biz_id = $("#bk_biz_id").val();
            var data = $(this).data();
            $.post('${SITE_URL}remove_check_host', {
                'bk_biz_id': bk_biz_id,
                'bk_host_innerip': data.ip
            }, function (res) {
                console.log(res);
                alert(res.message);
            })
        });
    });
</script>
</%block>